<template>
  <div>
    <a-card :bordered="false">
      <f-search-form @searchHandler="searchHandler">
        <f-search-form-item label="标题" name="demandTitle"/>
        <f-search-form-item label="企业" name="companyName"/>
        <f-search-form-item label="需求状态" name="onLineState" type="select" :data="api.status.onLineStatus"></f-search-form-item>
        <f-search-form-item label="联系方式" name="mobile" slot="advanced"/>
        <f-search-form-item label="发布日期" name="rangeDate" type="range" slot="advanced"/>
      </f-search-form>
      <f-table ref="table" size="default" rowKey="demandId" :columns="columns" handler="adminDemandListHandler" :operator="operator" :params="queryParam" :api="api.demand">
         <span slot="demandImages" slot-scope="text, record, index">
          <img :src="record.demandImages" v-viewer class="radius-img">
        </span>
        <span slot="solveState" slot-scope="text, record, index">
          <a-tag color="pink" v-if="text==0">未解决</a-tag>
          <a-tag color="#108ee9" v-else>已解决</a-tag>
        </span>
        <span slot="status" slot-scope="text, record, index">
          <a-switch v-model="record.onlineState==1" checkedChildren="上架" unCheckedChildren="下架" @change="(checked) => setStatus(checked,record)"/>
        </span>
        <span slot="action" slot-scope="text, record">
          <template>
            <a @click="$refs.demandDetails.getDetails(record.demandId)">查看</a>
            <a-divider type="vertical"/>
          </template>
          <a-dropdown>
            <a class="ant-dropdown-link">
              更多 <a-icon type="down"/>
            </a>
            <a-menu slot="overlay">
              <a-menu-item v-if="$auth('table.delete')">
                <a href="javascript:;" @click="$refs.table.remove(record.demandId)">删除</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </f-table>
      <demand-details ref="demandDetails"></demand-details>
    </a-card>
  </div>
</template>

<script>

  import DemandDetails from './demandDetails'

  export default {
    name: 'TableList',
    components: { DemandDetails },
    data () {
      return {
        //列表初始化查询参数
        queryParam: {},
        // 表头
        columns: [
          {
            title: '标题',
            width: 400,
            dataIndex: 'demandTitle'
          },
          {
            title: '封面图',
            dataIndex: 'demandImages',
            width: 90,
            align: 'center',
            scopedSlots: { customRender: 'demandImages' }
          },
          {
            title: '分类',
            width: 130,
            dataIndex: 'categoryName'
          },
          {
            title: '企业',
            width: 300,
            dataIndex: 'companyName',
            sorter: true
          },
          {
            title: '发布人',
            dataIndex: 'userName'
          },
          {
            title: '联系方式',
            dataIndex: 'mobile'
          },
          {
            title: '发布日期',
            dataIndex: 'publishDate'
          },
          {
            title: '上架状态',
            dataIndex: 'onLineState',
            sorter: true,
            width: 150,
            align: 'center',
            scopedSlots: { customRender: 'status' }
          },
          {
            title: '是否解决',
            dataIndex: 'solveState',
            width: 120,
            align: 'center',
            scopedSlots: { customRender: 'solveState' }
          },
          {
            title: '创建日期',
            width: 160,
            dataIndex: 'createTime',
            sorter: true
          },
          {
            title: '操作',
            dataIndex: 'action',
            width: '150px',
            scopedSlots: { customRender: 'action' }
          }
        ],
        //操作按钮
        operator: [
          {
            name: '删除',
            icon: 'delete',
            batch: true,
            handler: function (table) {
              table.remove()
            }
          }
        ]
      }
    },
    created () {

    },
    methods: {
      setStatus (check, record) {
        this.http.post(this, {
          url: this.api.demand.setOnLineState,
          data: {
            ids: record.demandId,
            onlineState: Number(check)
          },
          success (me, data) {
            record.onlineState = data
          }
        })
      }
    }
  }
</script>
